/* 
 * File:   Trapezium.cpp
 * Author: lgr013
 * 
 * Created on 13 de septiembre de 2014, 12:12
 */

#include "Trapezium.h"

Trapezium::Trapezium() {
}

Trapezium::Trapezium(ObjFactory *objFactory, bool flagStatic, float x, float y, float base, float height, double alpha, double beta, float mass, float rotation, int idImage) {
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    if (height < 0 || base < 0) {
        myLogFile->writeInLog(2, "[2] Tamaño del trapecio invalido (Base o altura negativo)\n");
    }

    Dot *dot = new Dot(x, y, base, height);

    Object *object = objFactory->getObjectTrapezium(flagStatic, dot->dotPixelsToWorld(), dot->sizeDotPixelsToWorld(), alpha, beta, mass, rotation);
    this->object = object;

    struct ObjectInit auxData;
    auxData.estatico = flagStatic;
    auxData.objectId = TRAPEZIUM;
    auxData.imageId = idImage;

    auxData.x = x;
    auxData.y = y;
    auxData.height = height;
    auxData.width = base;
    auxData.rot = rotation;

    auxData.idCharacter = VACIO;
    auxData.stateCharacter = VACIO;
    
    this->data = auxData;
    this->equals = false;
    myLogFile->writeInLog(0, "[0] Se ha creado un trapecio exitosamente\n");
    
    delete dot;
}

Trapezium::~Trapezium() {
    delete this->object;
}

void Trapezium::restartPlayer(){}

void Trapezium::checkChanges(){
    b2Vec2 pos = this->object->getPosition();
    if (this->data.x == pos.x && this->data.y == pos.y && this->data.rot  == this->object->getAngle()){
        this->equals = true;        
    }else{
        this->equals = false;        
    }

}


b2Vec2 Trapezium::getPosition() {
    return this->object->getPosition();
}

float Trapezium::getAngle() {
    return this->object->getAngle();
}

float Trapezium::getAngularVelocity() {
    return this->object->getAngularVelocity();
}

void Trapezium::setAngularVelocity(float velocity) {
    this->object->setAngularVelocity(velocity);
}

void Trapezium::setUbicDyn(int id){
    this->data.ubicDyn = id;
}

void Trapezium::updateData(){
    this->updatePosition();
    this->updateRotation();
}

void Trapezium::updateRotation(){
    this->data.rot = this->object->getAngle();
}

void Trapezium::updatePosition(){    
    b2Vec2 pos = this->object->getPosition();
    this->data.x = pos.x;
    this->data.y = pos.y;
    
}

struct ObjectInit Trapezium::getData(){
    this->updateData();
    return this->data;
}

b2Body* Trapezium::getBody() {
    return this->object->getBody();
    
}
bool Trapezium::getAreEquals(){
    return this->equals;
}
